<?php

namespace App\Http\Controllers\Admin;

use App\Http\Model\Product;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class ProductController extends Controller
{
	
	public function __construct()
	{
		$this->middleware('auth');
	}
	
	public function index(){
		$products = Product::all();

		return view('admin.products',['products' => $products]);
	}
	
	public function destroy($id){
		Product::destroy($id);
		return redirect('/admin/products');
	}
	
	public function newProduct(){
		return view('admin.new');
	}
	
	public function add(Request $request) {
		
		$file = $request->file('file');
		$extension = $file->getClientOriginalExtension();
		//Storage::disk('local')->put($file->getFilename().'.'.$extension,  File::get($file));
		
//		$entry = new \App\File();
//		$entry->mime = $file->getClientMimeType();
//		$entry->original_filename = $file->getClientOriginalName();
//		$entry->filename = $file->getFilename().'.'.$extension;
//
//		$entry->save();
		
		$product  = new Product();
		$product->file_id=1;
		$product->name =$request->input('name');
		$product->description =$request->input('description');
		$product->price =$request->input('price');
		$product->imageurl =$request->input('imageurl');
		
		$product->save();
		
		return redirect('/admin/products');
		
	}
	
	public function addUser(Request $request){
		
	}
}
